<style>
	@import "../../../common/css/adminHome.css";
</style>
<template>
	<view>
		<view class="admin_common_page">
			<view class="top_fix" style="height: 280rpx;">
				<view class="search_info">
				</view>
				<view class="">
					<view class="">
						<picker mode="selector" :range="list" :range-key="'endTime'" @change="change" :value="index"
							style="color:#fff;margin-left:20rpx;">
							<view class="">
								点击选择日期:
							</view>
							<view class="" style="display: flex;flex-direction:row;">
								<view style="border: 3px solid #ffff;width: 260rpx;margin-bottom: 20rpx;">
									{{list[index].endTime}}
								</view>
								<button type="default" size="mini" :id="list[index].id" @click.stop="caigou"
									style="height: 60rpx;">采购汇总</button>
								<button type="default" size="mini" :id="list[index].id" @click.stop="fenjian"
									style="height: 60rpx;">分拣汇总</button>
							</view>
						</picker>
					</view>
				</view>
				<view class="" v-for="(item, index) in lists" v-if="hidden">
					<uni-card @click="clickCard(item.agentShopId)" :title="item.agentShopName" mode="basic"
						:is-shadow="true">
						<view class="">
							商品名称：{{item.goodsName}}
						</view>
						<view class="">
							数量：{{item.goodsNumber}}
						</view>
					</uni-card>
				</view>
				<view class="" v-for="(item, index) in lists" v-if="!hidden">
					<uni-card @click="clickCard(item.agentShopId)" :title="item.agentShopName" mode="style"
						:is-shadow="true" :thumbnail="'https://cdn.shxc-sp.com'+item.agentShop.shopPic"
						:extra='`${item.status == 0 ? "未分拣" : "" }`' note="更多信息 >>">
						<view class="" @click="phone" :id="item.agentShop.phone" style="text-decoration: underline;">
							电话：{{item.agentShop.phone}}
						</view>
						<view class="">
							地址：{{item.agentShop.shopAddress}}
						</view>
					</uni-card>
				</view>
				<view class="" style="padding-bottom: 100rpx;">
				</view>
			</view>
		</view>
		<tabBarAdmin :pagePath="'/pages/admin/fenjian/fenjian'"></tabBarAdmin>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				hidden: true,
				id: null, //活动ID
				// fenjian:true,
				list: [], //活动列表
				index: 0,
				lists: [], //商铺列表内容

			}
		},
		methods: {
			//拨打电话
			phone(e) {
				console.log(e.currentTarget.id)
				uni.makePhoneCall({
					phoneNumber: e.currentTarget.id //仅为示例
				})
			},
			//点击卡片
			clickCard(e) {
				console.log(e)
				uni.navigateTo({
					url: '../../admin/caigoufenjian/caigoufenjian?agentShopId=' + e + "&activityId=" + this.id,
				});
			},
			change(e) {
				console.log(e)
				this.index = e.detail.value
			},
			caigou(e) {
				this.hidden = true
				console.log("采购汇总", e.currentTarget.id)
				let postData = {
					activityId: e.currentTarget.id
				}
				this.$api.caigou.purchase(postData)
					.then(res => {
						if (res.code == 200) {
							console.log("采购汇总99", res.rows.length)
							if (res.rows.length == 0) {
								uni.showToast({
									title: "没有更多内容",
									icon:"error",
									duration: 1500
								})
								this.lists = res.rows
							} else {
								this.lists = res.rows
							}
						} else {
							this.$commonJs.showToast.showNoneToast(res.err)
						}
					})
					.catch(err => {
						this.$commonJs.showToast.showNoneToast(err)
					})
			},
			fenjian(e) {
				console.log("分拣汇总", e.currentTarget.id)
				this.hidden = false
				let postData = {
					activityId: e.currentTarget.id
				}
				this.id = e.currentTarget.id
				this.$api.caigou.shopList(postData)
					.then(res => {
						if (res.code == 200) {
							console.log("分拣汇总", res.rows)
							if (res.rows.length == 0) {
								uni.showToast({
									title: "没有更多内容",
									icon:"error",
									duration: 1500
								})
								this.lists = res.rows
							} else {
								this.lists = res.rows
							}
							
						} else {
							this.$commonJs.showToast.showNoneToast(res.err)
						}
					})
					.catch(err => {
						this.$commonJs.showToast.showNoneToast(err)
					})
			},
		},
		mounted() {
			this.$api.caigou.activity()
				.then(res => {
					if (res.code == 200) {
						console.log(res.data)
						this.list = res.rows
					} else {
						this.$commonJs.showToast.showNoneToast(res.err)
					}
				})
				.catch(err => {
					this.$commonJs.showToast.showNoneToast(err)
				})
		}
	}
</script>
<style>
</style>
